package com.soboot.base.model;

import cn.hutool.core.util.ObjectUtil;
import com.soboot.base.model.BaseRole;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;
import java.util.List;

/**
 * @Author:
 * @createTime: 2022年09月19日 15:50:39
 * @version: 1.0
 * @Description: 基础用户信息
 * @Copyright:
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BaseUser extends User {

    private String nickName;

    private Integer id;

    private String deptName;

    private List<BaseRole> roles;

    private List<String> posts;

    public BaseUser(Integer id, String nickName, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.id = id;
        this.nickName = nickName;
    }

    public boolean isAdmin() {
        return ObjectUtil.equal(this.getUsername(),"admin");
    }
}
